package list;

import java.util.Scanner;

/**
 * Author:大鱼
 * gitee:https://gitee.com/TheInit/leetcode
 * csdn:https://blog.csdn.net/qq_40703471/article/details/124654707
 */

public class DeleteNode {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.substring(1, s.length() - 1).split(",");

        int[] nums = new int[split.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(split[i]);
        }
        ListNode node = ListUtil.getListFromArray(nums);
        ListNode cur = node;
        int val = sc.nextInt();
        while (cur != null) {
            if (cur.val == val) {
                deleteNode(cur);
            }
            cur = cur.next;
        }
        ListUtil.listToString(node);
    }

    public static void deleteNode(ListNode node) {
        //  修改要删除节点的值为下个节点的值
        node.val = node.next.val;
        //  删除下个节点
        node.next = node.next.next;
    }
}
